import request from '@/utils/httpRequest'
import { AxiosPromise } from 'axios'
import { DictTypePageResult, TypeDictFormI } from './dict_types'


const DICT_BASE_URL = "/api/v1/dict";

/**
 * 字典类型分页列表
 *
 * @param queryParams
 */
export function getDictTypePage(queryParams?: TypePageQueryI): AxiosPromise<DictTypePageResult> {
    return request({
        url: "/api/v1/dict/page",
        method: "get",
        params: queryParams,
      });
}


/**
 * 获取字典表单数据
 *
 * @param queryParams
 */
export function getFormData(id: number): AxiosPromise<TypeDictFormI> {
    return request({
        url: `${DICT_BASE_URL}/${id}/form`,
        method: "get",
      });
}

/**
 * 新增字典
 *
* @param data 字典表单数据
* @returns 请求结果
 */
export function add(data: TypeDictFormI): AxiosPromise<TypeDictFormI> {
    return request({
        url: `${DICT_BASE_URL}`,
        method: "post",
        data: data,
      });
}


  /**
   * 修改字典
   *
   * @param id 字典ID
   * @param data 字典表单数据
   * @returns 请求结果
   */
export function update(id: number, data: TypeDictFormI): AxiosPromise<TypeDictFormI> {
    return request({
        url: `${DICT_BASE_URL}/${id}`,
        method: "put",
        data: data,
      });
}

  /**
   * 删除字典
   *
   * @param ids 字典ID，多个以英文逗号(,)分隔
   * @returns 请求结果
   */
  export function deleteByIds(ids: string) {
    return request({
      url: `${DICT_BASE_URL}/${ids}`,
      method: "delete",
    });
  }

  /**
   * 获取字典的数据项
   *
   * @param typeCode 字典编码
   * @returns 字典数据项
   */
  export function getOptions(code: string) : AxiosPromise<TypeOptionI[]>{
    return request({
      url: `${DICT_BASE_URL}/${code}/options`,
      method: "get",
    });
  }